<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/js/miniui/themes/default/miniui.css"
	rel="stylesheet" type="text/css" />
<script src="/resources/js/jquery-1.6.2.min.js"
	type="text/javascript"></script>
<script src="/resources/js/miniui/miniui.js"
	type="text/javascript"></script>
<style type="text/css">
body {
	width: 100%;
	height: 100%;
	margin: 0;
	overflow: hidden;
}
.errorText{
	color: red;
}
</style>
</head>
<body>
	<div id="loginWindow" class="mini-window" title="用户登录"
		style="width: 450px; height: 165px;" showModal="true"
		showCloseButton="false">
		<div id="loginForm" >
			<table style="margin: auto;padding-top: 20px;">
				<tr>
					<td style="width: 60px;"><label for="phone$text">帐号：</label></td>
					<td><input id="phone" name="phone" class="mini-textbox"
						style="width: 150px;" /></td>
					<td><span class="errorText"></span></td>
				</tr>
				<tr>
					<td style="width: 60px;"><label for="pwd$text">密码：</label></td>
					<td><input id="pwd" name="pwd" class="mini-password"
						style="width: 150px;" /></td>
					<!-- <td><&nbsp;&nbsp;<a href="#">忘记密码?</a></td> -->
				</tr>
				<tr>
					<td></td>
					<td style="padding-top: 5px;"><a onclick="onLoginClick"
						class="mini-button" style="width: 60px;">登录</a> <a
						onclick="onResetClick" class="mini-button" style="width: 60px;">重置</a>
					</td>
					<td></td>
				</tr>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
	mini.parse();

	var loginWindow = mini.get("loginWindow");
	loginWindow.show();

	function onLoginClick(e) {
		var form = new mini.Form("#loginWindow");

		if (!formValid(form))
			return;

		$.ajax({
			url : "/user/login",
			data : form.getData(),
			type : "post",
			dataType : "json",
			success : function(ret) {
				if(ret.code == 0){
					loginWindow.hide();
					mini.loading("登录成功，马上转到系统...", "登录成功");
					setTimeout(function() {
						window.location = "/system/manager";
					}, 300);
				}else{
					mini.alert(ret.msg);
				}
			},
			error : function(jqXHR, textStatus, errorThrown) {
				mini.alert("登陆发生错误!");
			}
		});
		
	}

	function onResetClick(e) {
		var form = new mini.Form("#loginWindow");
		form.clear();
	}

	function formValid(form) {
		var json = form.getData();
		if (json.phone == "") {
			$(".errorText").empty().html("必须输入电话号码");
			return false;
		}

		if (json.pwd == "" || json.pwd.length < 6) {
			$(".errorText").empty().html("密码格式不对");
			return false;
		}
		
		return true;
	}
</script>

</html>